package com.farmpost.server.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.farmpost.server.pojo.Books;
import com.farmpost.server.pojo.RespBean;
import com.farmpost.server.service.IBooksService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.awt.print.Book;
import java.util.List;

/**
 * <p>
 * 书籍表 前端控制器
 * </p>
 *
 * @author king
 * @since 2022-04-08
 */
@RestController
@RequestMapping("/books")
public class BooksController {

    @Autowired
    private IBooksService iBooksService;

    @ApiOperation(value = "买or卖书")
    @PutMapping("/insertBooks")
    public RespBean insertBooks(@RequestBody Books books) {
        return iBooksService.insertBooks(books);
    }

    @ApiOperation(value = "查询售卖书籍信息")
    @GetMapping("/getBooksBySell")
    public List<Books> getBooksBySell() {
        return iBooksService.getBooksBySell();
    }

    @ApiOperation(value = "查询购买书籍信息")
    @GetMapping("/getBooksByBuy")
    public List<Books> getBooksByBuy() {
        return iBooksService.getBooksByBuy();
    }

    @ApiOperation(value = "查询全部书籍信息")
    @GetMapping("/Books")
    public List<Books> getBooks(@RequestParam Integer page) {
        Page<Books> booksPage = new Page<>(page, 20, false);
        return iBooksService.getBooks(booksPage);
    }

    @ApiOperation(value = "修改书籍信息")
    @PostMapping("/updateBooks")
    public RespBean updateBooks(@RequestBody Books books) {
        return iBooksService.updateBooks(books);
    }

    @ApiOperation(value = "根据id删除书籍信息")
    @DeleteMapping("/deleteBooks")
    public RespBean deleteBooks(@RequestParam(required = true) Integer id) {
        return iBooksService.deleteBooks(id);
    }
}
